import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

public class Task {

    public static void main(String[] args) throws Exception {
        run("lesson10/task2/src/config.properties");
    }

    public static void run(String fileName) throws IOException {
        // 读取config.properties
        Properties properties = new Properties();
        properties.load(new FileReader(fileName));

        // 获取配置信息
        System.out.println(properties.getProperty("username"));
        System.out.println(properties.getProperty("password"));
        System.out.println(properties.getProperty("nickname"));
        System.out.println(properties.getProperty("url"));

        // 修改配置信息
        properties.setProperty("username", "admin");

        // 新增配置信息
        properties.setProperty("age", "18");

        // 保存配置信息
        properties.store(new FileWriter(fileName), "更新后的配置");
    }

}